package com.wangle.spring.lifeCircle;

import lombok.ToString;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;

@ToString
public class User implements BeanNameAware, BeanFactoryAware, InitializingBean {

    private String name;

    private String phone;

    public User(){
        System.out.println("第一步：MyNBean实例化");
    }

    public void setName(String name){
        System.out.println("第二步：属性赋值");
        this.name = name;
    }



    public void init(){
        System.out.println("第六步：初始化bean");
    }



    public void destroy(){
        System.out.println("第七步：销毁bean");
    }


    @Override
    public void setBeanName(String name) {

        System.out.println("第三步：BeanNameAware Bean的名称是"+name);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("第三步：BeanFactoryAware beanFactory内容"+beanFactory.hashCode());
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        this.phone = "17269512816";
        System.out.println("InitializingBean 后置设置属性");
    }
}
